package com.order.test;

import com.chendx.store.common.constants.ampq.AMQPConstants;
import com.chendx.store.order.OrderApplication;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.amqp.AmqpException;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessagePostProcessor;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.core.env.Environment;
import org.springframework.test.context.junit4.SpringRunner;

/**
 * Created by chendx on 2022/4/24.
 */
@SpringBootTest(classes = OrderApplication.class)
@RunWith(SpringRunner.class)
public class Demo {

    @Autowired
    private Environment env;
    @Autowired
    private RabbitTemplate rabbitTemplate;
    @Test
    public void test(){
        rabbitTemplate.convertAndSend(env.getProperty(AMQPConstants.MQ_ORDER_QUEUE_ORDERTIMERDELAY), (Object) "order,1518110880003391488", new MessagePostProcessor() {
            @Override
            public Message postProcessMessage(Message message) throws AmqpException {
                message.getMessageProperties().setExpiration("10000");
                return message;
            }
        });
    }

}